/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package somatorioplugin;

import java.util.ArrayList;
import plugin.PluginBase;

/**
 *
 * @author Bush
 */
public class SomatorioPlugin extends PluginBase{

    private double somatorio;
    private ArrayList<Double> numeros;
    private SomatorioView view;
    
    public SomatorioPlugin(ArrayList<Double> numeros) throws Exception {
        super(numeros);        
    }

    public void calculaSomatorio(){
        for(int i=0; i<numeros.size();i++){
            somatorio += numeros.get(i).doubleValue();
        }
    }
    
    @Override
    public void setDados(ArrayList<Double> numeros) {
        this.numeros = numeros;
        calculaSomatorio();
    }
   
    @Override
    public void preprocessa() {
        
    }

    @Override
    public void posprocessa() {
        view = new SomatorioView();
        view.getTxtResultado().setText(String.valueOf(somatorio));
        view.getLstNumeros().setListData(numeros.toArray());
        view.setLocationRelativeTo(view);
        view.setVisible(true);
    }
    
}
